package cn.itsource.producer;

import cn.itsource.ymcc.constant.PayConstants;
import cn.itsource.ymcc.constant.RConst;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class PayProducerImpl implements PayProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    @Override
    public void updatePayOrderStatus(Map<String, String> map) {
        rocketMQTemplate.syncSend(PayConstants.MQ_TOPIC_PAYORDER_PAYORDER+ RConst.Str.COLON+PayConstants.MQ_TAGS_PAYORDER_PAYORDER,
                MessageBuilder.withPayload(JSON.toJSONString(map)).build());
    }

    @Override
    public void payTimeout(String orderNo) {
        rocketMQTemplate.syncSend(PayConstants.MQ_TOPIC_PAYORDER_TIMEOUT_PAYORDER+ RConst.Str.COLON+PayConstants.MQ_TAGS_PAYORDER_TIMEOUT_PAYORDER,
                MessageBuilder.withPayload(orderNo).build(),2000,5);
    }
}